home *** CD-ROM | disk | FTP | other *** search
- /* Gray Matter
- * Written at MacHack 2000 by Allon Stern
- * FREEWARE
- * Feel free to use this code for working your own hacks, or
- * extend the functionality!
- * However, please don't distribute modified versions as "Gray Matter" or
- * under my name.
- * If you have ideas you want me to incorporate into Gray Matter, send me
- * email at allon+palm@radioactive.org
- */
-
-
- #include <Pilot.h>
- #include <SysEvtMgr.h>
- #include <Graffiti.h>
- #include <WindowNew.h>
-
- /***********************************************************************
- *
- * Internal Constants
- *
- ***********************************************************************/
- #define kHackFileCreator 'GrMr'
- #define kHackCodeID 1001
-
- /***********************************************************************
- *
- * Function Prototypes
- *
- ***********************************************************************/
-
- char GetScreenValue(DWord *bits, DWord x, DWord y);
- void SetScreenValue(DWord *bits, DWord x, DWord y, DWord newvalue);
- void AntiAliasPixel(DWord *bits, DWord x, DWord y);
-
-
- void MyScrDrawChars(WinPtr pWindow, SWord xLoc, SWord yLoc, SWord xExtent, SWord yExtent,
- SWord clipTop, SWord clipLeft, SWord clipBottom, SWord clipRight,
- const Char * const chars, Word len, FontPtr fontPtr);
-
-
- void MyScrDrawChars(WinPtr pWindow, SWord xLoc, SWord yLoc, SWord xExtent, SWord yExtent,
- SWord clipTop, SWord clipLeft, SWord clipBottom, SWord clipRight,
- const Char * const chars, Word len, FontPtr fontPtr)
- {
- void (*oldtrap)(WinPtr, SWord, SWord, SWord, SWord,
- SWord, SWord, SWord, SWord,
- const Char * const, Word, FontPtr);
- DWord temp; // for the feature manager call type checking
- Err err;
- Byte data = 0;
- DWord *bits;
- SWord x,y,tox,toy;
- SWord maxLineHeight;
- RectangleType um;
- GDevicePtr theGWorld;
-
- // Get the address of the old routine from HackMaster:
- err = FtrGet(kHackFileCreator,kHackCodeID,&temp);
- ErrFatalDisplayIf(err, "can't get real trap address");
- oldtrap=(void (*)(WinPtr, SWord, SWord, SWord, SWord,
- SWord, SWord, SWord, SWord,
- const Char * const, Word, FontPtr))temp;
-
-
- oldtrap (pWindow, xLoc, yLoc, xExtent, yExtent,
- clipTop, clipLeft, clipBottom, clipRight,
- chars, len, fontPtr);
-
- theGWorld = pWindow->gDeviceP;
- bits = (DWord *)theGWorld->baseAddr;
- maxLineHeight = fontPtr->fRectHeight;
- x = xLoc;
- y = yLoc;
- tox = xExtent + xLoc;
- toy = yExtent + yLoc;
-
- /*
- typedef struct {
- SWord x;
- SWord y;
- } PointType;
-
-
- typedef struct {
- PointType topLeft;
- PointType extent;
- } RectangleType;
- */
- um.topLeft.x = x;
- um.topLeft.y = y;
- um.extent.x = xExtent;
- um.extent.y = yExtent;
- // WinDrawRectangle(&um, 3);
-
-
- if (theGWorld->pixelSize == 1) {
- DWord i,j;
- for (i = x; i <= tox; i++) {
- for (j = y; j <= toy; j++) {
- DWord bitnum;
- DWord value;
- DWord mask;
- bitnum = 160 * j + i;
- mask = 0x00000001L << (31 - bitnum % 32);
- value = bits[(bitnum / 32)] & mask;
- if (value)
- bits[bitnum/32] &= ~mask;
- else
- bits[bitnum/32] |= mask;
- }
- }
- } else {
- DWord i,j;
- for (i = x; i <= tox; i++) {
- for (j = y; j <= toy; j++) {
-
-
- /*
- DWord bitnum;
- DWord value;
- DWord mask;
- bitnum = 160 * j + i;
- mask = 0x00000003L << (30 - (bitnum % 16)*2 );
- value = bits[(bitnum / 16)] & mask;
- // if (value)
- */
- // if (!GetScreenValue(bits, i, j))
- // SetScreenValue(bits, i, j, 0x01);
- /*
- bits[bitnum/16] &= ~mask;
- else
- bits[bitnum/16] |= mask;
-
- */
- if (!GetScreenValue(bits, i, j))
- AntiAliasPixel( bits, i, j);
-
- }
- }
-
- }
-
-
-
- }
-
- void AntiAliasPixel(DWord *bits, DWord x, DWord y)
- {
- DWord total = 0;
- DWord top = 0;
- DWord left = 0;
- DWord bottom = 0;
- DWord right = 0;
-
-
- if (GetScreenValue(bits, x-1, y-1) ==0x03) {
- total++;
- top++;
- left++;
- }
-
- if (GetScreenValue(bits, x-1, y) ==0x03) {
- total++;
- top++;
- }
-
- if (GetScreenValue(bits, x-1, y+1) ==0x03) {
- total++;
- top++;
- right++;
- }
-
- if (GetScreenValue(bits, x, y-1) ==0x03) {
- total++;
- left++;
- }
-
- if (GetScreenValue(bits, x, y+1) ==0x03) {
- total++;
- right++;
- }
-
- if (GetScreenValue(bits, x+1, y-1) ==0x03) {
- total++;
- bottom++;
- left++;
- }
-
- if (GetScreenValue(bits, x+1, y) ==0x03) {
- total++;
- bottom++;
- }
-
- if (GetScreenValue(bits, x+1, y+1) ==0x03) {
- total++;
- bottom++;
- right++;
- }
-
- if ((top && bottom) || (left && right))
- return;
-
- if ((top > 1) || (bottom > 1) || (left > 1) || (right > 1)) {
- if (total >= 3)
- SetScreenValue(bits, x, y, 0x01);
- return;
- }
-
- if (total == 2)
- SetScreenValue(bits, x, y, 0x01);
-
- }
-
- char GetScreenValue(DWord *bits, DWord x, DWord y)
- {
- DWord bitnum;
- DWord value;
- DWord mask;
- bitnum = 160 * y + x;
- mask = 0x00000003L << (30 - (bitnum % 16)*2 );
- value = ((bits[(bitnum / 16)]) >> (30 - (bitnum % 16)*2)) & 0x03;
- return value;
- }
-
- void SetScreenValue(DWord *bits, DWord x, DWord y, DWord newvalue)
- {
- DWord bitnum;
- DWord mask;
-
- bitnum = 160 * y + x;
- mask = 0x00000003L << (30 - (bitnum % 16)*2 );
- bits[(bitnum/16)] &= ~mask;
- bits[(bitnum/16)] |= (newvalue & 0x00000003L) <<(30 - (bitnum % 16)*2);
- }
-